#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 55;

int n, m;
string s;
int a[55];
int dp[N][N][26];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  n = s.size();
  rep(i, 1, n) a[i] = s[i - 1] - 'A';
  rep(c, 0, 25) rep(i, 1, n) dp[i][i][c] = a[i] == c ? 0 : 1;
  rep(len, 2, n) {
    rep(l, 1, n + 1 - len) {
      int r = l + len - 1;
      rep(c, 0, 25) {
        dp[l][r][c] = 100;
        if (a[l] != c && a[r] != c)
          dp[l][r][c] = 1 + min(dp[l + 1][r][a[l]], dp[l][r - 1][a[r]]);
        rep(i, l, r - 1) dp[l][r][c] =
            min(dp[l][r][c], dp[l][i][c] + dp[i + 1][r][c]);
      }
    }
  }
  int ans = 100;
  rep(c, 0, 25) ans = min(ans, dp[1][n][c]);
  ans++;
  cout << ans;
  return 0;
}